Repository navigation
Studio: an OpenCode session shows its context size (#719) - #787
Merged
Merged
Conversation
OpenCode's plugin keeps the latest step's input tokens (session.step.ended's input + cache.read + cache.write) on each top-level turn and sends them on the turn's end as context_tokens. The adapter reads them into the session's context; a subagent's or a late end, and an end without a count, keep it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CVqACdAVieHSJNHrmEc2Xd
A step with zero or no tokens keeps the turn's last count; the dev and vocabulary docs and follow_process's comment name the new source; the new test reuses server_line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CVqACdAVieHSJNHrmEc2Xd
danielrispler
added a commit
that referenced
this pull request
Nov 28, 2026
Resolves #719's OpenCode context size (#787) with #779's held wake-up: a top-level turn's end goes through the recorder's send, after its held wake-up, and carries context_tokens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CVqACdVnKiSXskgVojtEiA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #719.
Summary
An OpenCode session now shows its context size. The plugin keeps the latest step's input tokens on each top-level turn and sends them on the turn's end. The core puts them where Claude Code's transcript puts its count.
An end without
context_tokens(the turn ended before any step did, or a log from before this change) leaves the session's last size as it was. The UI needed no change: the row mark readstranscript.contextwhatever the agent is, and the "reports no context size" note goes away because it followscapabilities.context.Evidence
New real fixture
core/tests/fixtures/opencode/context.jsonl: OpenCode 2.4.2's service, 2026-11-28. Turn 1 reads, writes and runs a command; turn 2 starts a background subagent, whose result wakes the session. A scratch capture plugin beside it logged everysession.step.ended(the raw files are inlocal-evidence/2026-11-28-issue-719-opencode-context/):context_tokenssentinput + cache.read + cache.writeBefore:
a_turn_ends_count_is_the_sessions_context_size_and_an_end_without_one_keeps_itfailed witha later end's count: left: None, right: Some(13000).After: all 10
opencodetests pass:npm run checkpasses.Tests: two new ones, the fixture replay and the table, and one assertion added to
the_recorded_run_replays_into_its_sessions_turns_and_tools. None were removed or merged.The recording had a catch: with Daniel's installed user-level plugin present, a project-level copy with the same
id: "plotkeeper"recorded nothing. The scratch copy was renamed toplotkeeper-rec-719. This only matters for recording fixtures; a real install has one copy.Correctness pass
/code-review highran a standards axis and a spec axis, with state, ordering and stored-data tracing, and both tests run.tokenswould have set the count to 0. It is now|| turn.context. This was unverified that OpenCode ever sends one.docs/studio/development.md,docs/studio/CONTEXT.md("Context size") andfollow_process's doc comment didn't name the new source. The new test also reusesserver_lineinstead of copying it.ended, the subagent and late conditionals could be one branch per case;Happened::Contextcould carrytranscript::Contextrather thanu64. Both are judgement calls.context: true. An old build reading new state shows the count next to its stale note. No new stored fields.Outside review
gemini-4-neon-medium: 0 findings.
cost: 2.6 min, 273480 tokens; Gemini quota left: weekly 55% to 54%, 5h 93% to 89%. It reviewed the first commit; the review-fix commit was made while it ran, so it printedwarning: the reviewed checkout changed during the review.Merge Danger
Door: two-way
The new line field is optional on both sides. Old logs replay as before, and a new log read by an old build ignores the field.
Blast Radius: OpenCode-only
Only OpenCode sessions change: their header gains a token count. Daniel's installed plugin picks up the change on plotkeeper's next start (the rewire on start, #438).
🤖 Generated with Claude Code
https://claude.ai/code/session_01CVqACdAVieHSJNHrmEc2Xd